﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace Bank.Operations
{
    //TODO: currently it uses canned values for ranges and amounts, modify so that these are modifiable parameters
    public class RangeInterestCalculator : IInterestCalculator
    {
        public void CalculateInterest(IAccount account)
        {
            Contract.Requires(account != null);
            Contract.Requires(account.Ballance > 0m);

            if (account.Ballance < 1000)
            {
                var result = Math.Round((account.Ballance * 0.02m), 2);

                account.Ballance += result;
            }

            if (account.Ballance > 2000)
            {
                var result = Math.Round((1000 * 0.02m), 2);

                account.Ballance += result;

                result = Math.Round((1000 * 0.03m), 2);

                account.Ballance += result;

                var above2000 = account.Ballance - 2000;

                result = Math.Round((above2000 * 0.04m), 2);

                above2000 = above2000 * 0.04m;

                account.Ballance += result;
            }

            if (account.Ballance >= 1000 || account.Ballance <= 2000)
            {
                var above1000 = account.Ballance - 1000;

                var result = Math.Round((above1000 * 0.03m), 2);

                above1000 = result;

                result = Math.Round((1000 * 0.02m), 2);

                account.Ballance += result;

                account.Ballance += above1000;
            }
        }

        public void CalculateInterest2(IAccount account)
        {
            Contract.Requires(account != null);
            Contract.Requires(account.Ballance2 > 0m);

            if (account.Ballance2 < 1000)
            {
                //var result = Math.Round((account.Ballance2 * 0.02m), 2);

                account.Ballance2 += Money.Round((account.Ballance2 * 0.02m), 2); ;
            }

            if (account.Ballance2 > 2000)
            {
                var result = Math.Round((1000 * 0.02m), 2);

                account.Ballance2 += result;

                result = Math.Round((1000 * 0.03m), 2);

                account.Ballance2 += result;

                var above2000 = account.Ballance2 - 2000;

                Money moneyResult = new Money();
                moneyResult  = Money.Round((above2000 * 0.04m), 2);

                above2000 = above2000 * 0.04m;

                account.Ballance2 += moneyResult;
            }

            if (account.Ballance2 >= 1000 || account.Ballance2 <= 2000)
            {
                var above1000 = account.Ballance2 - 1000;              

                above1000 = Money.Round((above1000 * 0.03m), 2);

                var result1 = Math.Round((1000 * 0.02m), 2);

                account.Ballance2 += result1;

                account.Ballance2 += above1000;
            }
        }


    }
}
